#pragma once
#include "Shader.h"
#include "MeshDrawingPolicy.h"
#include "MaterialParameter.h"
#include "RenderView.h"
class VertexFactoryParam;

//
// BasePassVertexShader
//
class BasePassVertexShader : public Shader
{
public:
	BasePassVertexShader();
	virtual ~BasePassVertexShader();

	static const ShaderType StaticType;
	virtual const ShaderType* getShaderType() const { return &StaticType; }

	static bool ShouldCache(const class Material*) { return true; }
	static Shader* Create() { return new BasePassVertexShader(); }
	static void Define(ShaderDefineMap* defineMap) {}
	
	virtual bool Init();
	virtual void SetRenderable(RenderView* view, Renderable* renderable);

private:
	ShaderParameter mWorldMatrixParam;
	VertexFactoryParam *mVertexFactoryParam;
};

class BasePassPixelShader : public Shader
{
public:
	static const ShaderType StaticType;
	virtual const ShaderType* getShaderType() const { return &StaticType; }

	static bool ShouldCache(const class Material*) { return true; }
	static Shader* Create() { return new BasePassPixelShader(); }
	static void Define(ShaderDefineMap* defineMap) {}
	
	void Bind(const VertexFactory* vertexFactory, const Material* material);

	void SetRenderable(RenderView* view, Renderable* renderable);

private:
	MaterialParameterRefList mMaterialParamRefs;
};


//
// BasePassDrawingPolicy
//
class BasePassDrawingPolicy : public MeshDrawingPolicy
{
public:
	BasePassDrawingPolicy(const VertexFactory* vertexFactory, const Material* material);

	bool Compare(const BasePassDrawingPolicy& other) const
	{
		DRAWINGPOLICY_COMPARE(mVertexFactory);
		DRAWINGPOLICY_COMPARE(mMaterial);

		DRAWINGPOLICY_COMPARE(mVertexShader);
		DRAWINGPOLICY_COMPARE(mPixelShader);
		return false;
	}

	void DrawShared(BoundShaderStatePtr& boundShaderState);
	void DrawRenderable(RenderView* view, Renderable* renderable);

	BoundShaderStatePtr CreateBoundShaderState();

protected:
	BasePassVertexShader* mVertexShader;
	BasePassPixelShader* mPixelShader;
};
